package com.tentcent.yumeko;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;


@RestController
@RequestMapping("/consumer")
public class ConsumerController {

    @Autowired
    private RestTemplate restTemplate;
    @Autowired
    private ProducerService producerService;

    /**
     * Get sum of two value.
     * @param value1 value 1
     * @param value2 value 2
     * @return sum
     */
    //http://localhost:22222/consumer/feign?value1=2&value2=2
    @GetMapping("/feign")
    public int feign(@RequestParam int value1, @RequestParam int value2) {
        return producerService.sum(value1, value2);
    }

    /**
     * Get information of producer
     * @return information of producer
     */
    //http://localhost:22222/consumer/rest
    @GetMapping("/rest")
    public String rest() {
        return restTemplate.getForObject(
                "http://DiscoverProducerService/producer/info",
                String.class);
    }

    /**
     * Bootstrap.yaml配置的访问
     * @return health check info
     */
    @GetMapping("/healthCheck")
    public String healthCheck() {
        return "pk ok";
    }
}
